package com.cn.jwt.zy.jwt.resolver;

import org.springframework.core.MethodParameter;
import org.springframework.lang.Nullable;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

import java.lang.reflect.Parameter;

/**
 * 消息处理
 *
 * @author zhangyi
 * @date 2018/12/14 15:05
 */
@Component
public class MyResolver  implements HandlerMethodArgumentResolver {

    @Override
    public boolean supportsParameter(MethodParameter methodParameter) {
        Parameter parameter = methodParameter.getParameter();
        String name = parameter.getName();
        System.out.println("接受消息参数:"+name);
        return false;
    }

    @Nullable
    @Override
    public Object resolveArgument(MethodParameter methodParameter,
                                  @Nullable ModelAndViewContainer modelAndViewContainer,
                                  NativeWebRequest nativeWebRequest,
                                  @Nullable WebDataBinderFactory webDataBinderFactory) throws Exception {
        String parameterName = methodParameter.getParameterName();
        String viewName = modelAndViewContainer.getViewName();
        System.out.println("参数:"+parameterName+"视图:"+viewName);
        return null;
    }
}
